package org.auto2;

import org.opencv.core.Core;
import org.test.GPSPoint;
import org.test.TraceBoundaryProcessor;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class DBSCAN_Test {

    public static void main(String[] args) throws Exception {

        // 加载 opencv_javaXX.dll
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        // GPS点集合
        List<GPSPoint> gpsPointList = new ArrayList<>();

        InputStream is = DBSCAN_Test.class.getResourceAsStream("/data2.txt");
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = null;
        br.readLine(); //跳过标题行
        Integer idx = 0;
        while ((line = br.readLine()) != null) {
            // 进行抽稀
            String[] arr = line.split("\\s+");
            GPSPoint rawPoint = new GPSPoint(Double.parseDouble(arr[0]), Double.parseDouble(arr[1]));
            gpsPointList.add(rawPoint);
        }

        // 调用分类方法，返回多个类别
        List<Collection<GPSPoint>> list = DBSCAN.clusterGPSPoints(gpsPointList, 100, 30);
        double totalArea = 0;
        for (Collection<GPSPoint> traces : list) {
            if (traces.size() < 3) {
                continue;
            }

            Map<String, Object> map = TraceBoundaryProcessor.getTracesBoundaries(traces, 1, 1, 1, 4000, true, false);
            double area = Double.parseDouble(map.get("area") + "");
            totalArea += area;
        }

        System.out.println("Total area: " + totalArea);

    }
}
